Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): allow non sidebar category to be first item of sidebar #2032

Merged
merged 6 commits into from
Nov 24, 2019

Conversation

endiliey
Copy link
Contributor

@endiliey endiliey commented Nov 23, 2019

Motivation

This allows user to define sidebar item as the first level item of a sidebar. If previously its defined like this

type Sidebar = {
  [sidebarId: string]: {
    [sidebarCategory: string]: SidebarItem[];
  }
}

Its now

type Sidebar = {
  [sidebarId: string]: {
    [sidebarCategory: string]: SidebarItem[];
  } | SidebarItem[];
}

Other changes

  • I added a lot of other tests in sidebars. So now if there is any wrong type of 'label', 'items', unknown type and so on, user will receive MUCH BETTER error messages. This is still 100% test coverage on docs
    Updated babel so i can use TS 3.7 assertion
  • Docs updated

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

all test pass

// sidebars.js
module.exports = {
    docs: [
    {
      type: 'category',
      label: 'Docusaurus',
      items: ['introduction', 'design-principles', 'contributing'],
    },
    {
      type: 'category',
      label: 'Getting Started',
      items: ['installation', 'configuration'],
    },
    'creating-pages',
    'cli',
     {
        type: 'category',
        label: 'Plugins',
        items: ['using-plugins', 'advanced-plugins'],
      },
  ],
};

first item not category

Here's a cool demo showing it. You can directly click "Creating Pages"
gif sidebar item

@endiliey endiliey added the pr: new feature This PR adds a new API or behavior. label Nov 23, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 23, 2019
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Nov 23, 2019

Deploy preview for docusaurus-2 ready!

Built with commit 0b931e4

https://deploy-preview-2032--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Nov 23, 2019

Deploy preview for docusaurus-preview ready!

Built with commit 0b931e4

https://deploy-preview-2032--docusaurus-preview.netlify.com

website/docs/sidebar.md Outdated Show resolved Hide resolved
website/docs/sidebar.md Outdated Show resolved Hide resolved
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests

@@ -171,19 +171,16 @@ function DocSidebar(props) {
)}
</button>
<ul className="menu__list">
{sidebarData.map(
item =>
item.items.length > 0 && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need to check anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the first item is not a category, items is undefined. Checking is alrd done in the DocSidebarItem itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this loc removal, it will error

@yangshun
Copy link
Contributor

Ok please resolve conflicts and self-merge :D

@endiliey
Copy link
Contributor Author

Yeah that will have to wait maybe tonight. I have plans for today

@yangshun yangshun merged commit 9862a68 into master Nov 24, 2019
@endiliey endiliey deleted the endi/sidebaritem branch November 24, 2019 10:38
@flaurida
Copy link

flaurida commented Dec 2, 2019

thank you! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants